<template>
  <div>
    <!-- 面包屑 -->
    <div class="crumbs">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }"><i class="el-icon-s-fold"></i> 首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单评价</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 表单 -->
    <el-card shadow="always">
      <!-- 表头 -->
      <div slot="header">
        <el-form label-width="100px">
          <el-form-item label="订单编号:">
            <el-input v-model="id" placeholder="请输入订单编号" size="medium" style="width: 350px;"></el-input>
          </el-form-item>
          <el-form-item label="服务内容:">
            <el-input v-model="serviceitem" placeholder="请输入服务内容" size="medium" style="width: 350px;"></el-input>
          </el-form-item>
          <el-form-item label="订单时间:" size="normal">
            <div class="block">
              <el-date-picker v-model="timeArr" type="daterange" clearable range-separator="至" start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item label="订单星级:">
            <el-select v-model="level" placeholder="请选择评价星级" size="medium" style="width: 350px;">
              <el-option label="一星" :value="1"></el-option>
              <el-option label="二星" :value="2"></el-option>
              <el-option label="三星" :value="3"></el-option>
              <el-option label="四星" :value="4"></el-option>
              <el-option label="五星" :value="5"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-button type="primary" size="medium" @click="getSearchComment">筛选</el-button>
        <el-button size="medium" @click="clearSearch">清空筛选条件</el-button>
      </div>
      <!-- 表体 -->
      <!-- 表格 -->
      <el-table :data="tableData" v-loading="loading" border style="width: 100%" size="medium">
        <el-table-column prop="id" label="订单编号" align="center">
        </el-table-column>
        <el-table-column prop="serviceitem" label="服务内容" align="center">
        </el-table-column>
        <el-table-column prop="username" label="评价者" align="center">
        </el-table-column>
        <el-table-column prop="level" label="星级" align="center">
        </el-table-column>
        <el-table-column prop="address" label="图片" align="center">
          <template slot-scope="{row}">
            <img v-for="imgSrc in row.img.split(',')" :src="'http://www.img.ttblog.cn/'+imgSrc" alt="" style="width:70px;height: 70px;">
          </template>
        </el-table-column>
        <el-table-column prop="commentcontent" label="评价内容" align="center">
        </el-table-column>

        <el-table-column prop="time" label="评价时间" align="center">
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination style="text-align:center;margin-top: 20px;" @current-change="getIndentComment"
        @size-change="getIndentComment" :current-page.sync="pageInfo.pageNum" :page-sizes="[3, 5, 10, 20]"
        :page-size.sync="pageInfo.pageSize" layout="prev, pager, next,total,jumper,->, sizes" :total="pageInfo.total"
        :pager-count="7">
      </el-pagination>

    </el-card>
  </div>
</template>

<script>
export default {
  name: "IndentJudge",
  data() {
    return {
      pageInfo: {
        pageNum: 1,
        pageSize: 3,
        total: 20,
      },
      timeArr: [],
      id: '',
      serviceitem: '',
      level: '',
      tableData: [],
      loading:false,
    }
  },
  mounted() {
    this.getIndentComment()
  },
  methods: {
    async getIndentComment() {
      this.loading = true;
      let { pageNum, pageSize } = this.pageInfo;
      let { starttime, endtime, id, serviceitem, level } = this;
      let query = this.$QS.stringify({ pageNum, pageSize, starttime, endtime, id, serviceitem, level });
      let res = await this.$API.Indent.reqIndentComment(query);
      if (res.code == 200) {
        this.pageInfo.total = res.data.total;
        this.tableData = res.data.list;
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
        this.$message({message: '没有数据',type: 'error'})
      }
      this.loading=false;
    },
    async getSearchComment() {
      this.pageInfo.pageNum = 1;
      await this.getIndentComment();
      if (this.tableData.length > 0) {
        this.$message({ message: '筛选成功', type: 'success' })
      }
    },
    clearSearch() {
      this.id = '';
      this.serviceitem = '';
      this.level = '';
      this.timeArr = [];
      this.pageInfo.pageNum = 1;
      this.getIndentComment();
    },
  },
  computed: {
    starttime() {
      if (this.timeArr.length > 0) {
        return this.timeArr[0]
      } else {
        return '';
      }
    },
    endtime() {
      if (this.timeArr.length > 0) {
        return this.timeArr[1]
      } else {
        return '';
      }
    },
  },
  watch: {
    timeArr() {
      if (!this.timeArr) {
        this.timeArr = [];
      }
    },
  },
}
</script>

<style scoped></style>